package com.pro.controller;

import com.google.gson.Gson;
import com.pro.pojo.JsSearchKeyWords;
import com.pro.pojo.JsonData;
import com.pro.service.JsKeyWordHeatStatisticsService;
import com.pro.utils.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ClassName:JsKeyWordHeatStatisticsController
 * Package:com.pro.controller
 * Description:
 *
 * @Date:2021/12/8 19:46
 * @Author: XJR
 */
@RestController
@RequestMapping("/JsKeyWordHeatStatistics")
public class JsKeyWordHeatStatisticsController {
    @Autowired
    private JsKeyWordHeatStatisticsService service;

    @Autowired
    private RedisCache redisCache;

    private Gson gson = new Gson();

    //查看关键字热度统计
    @RequestMapping("/selectKeyWords")
    public JsonData selectKeyWords(){
        List<JsSearchKeyWords> jsSearchKeyWords = service.selectKeyWords();
        String selectKeyWords = redisCache.getCacheObject("selectKeyWords");
        List<JsSearchKeyWords>  list = gson.fromJson(selectKeyWords, List.class);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务端错误");
    };
}
